﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace VLog
{
    internal class LogCommons
    {
        /// <summary>
        /// 
        /// </summary>
        /// <returns>返回默认的txt地址</returns>
        public static string GetPath()
        {
            return GetPath(PathType.Txt);
        }

        /// <summary>
        /// 根据地址类型 获取实际地址 或是 数据库连接字符串
        /// </summary>
        /// <param name="pathType">地址类型PathType</param>
        /// <returns>返回 实际地址 或是 数据库连接字符串</returns>
        public static string GetPath(PathType pathType)
        {
            switch (pathType)
            {
                case PathType.Xml:
                    return string.Format("{0}{1}", AppDomain.CurrentDomain.BaseDirectory, "vlog.xml");
                case PathType.Txt:
                    return string.Format("{0}{1}", AppDomain.CurrentDomain.BaseDirectory, "vlog.txt");
                case PathType.DataBase:
                    return
                        string.IsNullOrEmpty(
                            ConfigurationManager.ConnectionStrings["VLogConnectionString"].ConnectionString
                        )
                        ?
                        "server=.;user id=sa;password=;Pooling=true;"
                        :
                        ConfigurationManager.ConnectionStrings["VLogConnectionString"].ConnectionString;
                default:
                    return "windows日志（网站日志）";
            }
        }

    }
    /// <summary>
    /// 日志地址类型
    /// </summary>
    internal enum PathType
    {
        /// <summary>
        /// Txt日志
        /// </summary>
        Txt,
        /// <summary>
        /// XML日志
        /// </summary>
        Xml,
        /// <summary>
        /// 数据库日志
        /// </summary>
        DataBase,
        /// <summary>
        /// windows日志
        /// </summary>
        WindowsEvent,
    }

}
